<template>
  <div class="app-container">
    <PlatformHeader />
    <div class="profile-content">
      <el-row :gutter="20" class="profile-row">
        <el-col :span="8" :xs="24">
          <el-card class="user-card info-card" shadow="hover">
            <div slot="header" class="card-header">
              <i class="el-icon-user-solid header-icon"></i>
              <span>个人信息</span>
            </div>
            <div class="user-avatar-container">
              <div class="user-avatar">
                <i class="el-icon-user"></i>
              </div>
              <div class="user-name">{{ user.userName }}</div>
              <div class="user-role">{{ roleGroup }}</div>
            </div>
            <ul class="info-list">
              <li class="info-item">
                <div class="info-icon">
                  <i class="el-icon-phone"></i>
                </div>
                <div class="info-content">
                  <div class="info-label">手机号码</div>
                  <div class="info-value">{{ user.phonenumber || '未设置' }}</div>
                </div>
              </li>
              <li class="info-item">
                <div class="info-icon">
                  <i class="el-icon-message"></i>
                </div>
                <div class="info-content">
                  <div class="info-label">用户邮箱</div>
                  <div class="info-value">{{ user.email || '未设置' }}</div>
                </div>
              </li>
              <li class="info-item">
                <div class="info-icon">
                  <i class="el-icon-office-building"></i>
                </div>
                <div class="info-content">
                  <div class="info-label">所属部门</div>
                  <div class="info-value" v-if="user.dept">{{ user.dept.deptName }}</div>
                </div>
              </li>
              <li class="info-item">
                <div class="info-icon">
                  <i class="el-icon-timer"></i>
                </div>
                <div class="info-content">
                  <div class="info-label">创建日期</div>
                  <div class="info-value">{{ user.createTime }}</div>
                </div>
              </li>
            </ul>
          </el-card>
        </el-col>
        <el-col :span="16" :xs="24">
          <el-card class="detail-card info-card" shadow="hover">
            <div slot="header" class="card-header">
              <i class="el-icon-s-tools header-icon"></i>
              <span>账户管理</span>
            </div>
            <el-tabs v-model="activeTab" class="profile-tabs">
              <el-tab-pane name="userinfo">
                <span slot="label" class="tab-label">
                  <i class="el-icon-document"></i> 基本资料
                </span>
                <userInfo :user="user" />
              </el-tab-pane>
              <el-tab-pane name="resetPwd">
                <span slot="label" class="tab-label">
                  <i class="el-icon-lock"></i> 修改密码
                </span>
                <resetPwd />
              </el-tab-pane>
            </el-tabs>
          </el-card>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
import userInfo from "./userInfo";
import resetPwd from "./resetPwd";
import { getUserProfile } from "@/api/system/user";
import PlatformHeader from '../../../../components/PlatformHeader/index.vue';

export default {
  name: "Profile",
  components: { userInfo, resetPwd, PlatformHeader },
  data() {
    return {
      user: {
        userName: '',
        phonenumber: '',
        email: '',
        dept: {},
        createTime: ''
      },
      roleGroup: '',
      postGroup: '',
      activeTab: "resetPwd" //  userinfo
    };
  },
  created() {
    this.getUser();
    const hasUpperCase = this.$store.state.user.passwordHasUpperCase;
    if(hasUpperCase){
      this.activeTab = 'userinfo'
    }
  },
  methods: {
    getUser() {
      getUserProfile().then(response => {
        this.user = response.data;
        this.roleGroup = response.roleGroup;
        this.postGroup = response.postGroup;
      }).catch(error => {
        console.error("获取用户信息失败:", error);
      });
    }
  }
};
</script>

<style scoped lang="scss">
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: url('../../../assets/images/bgn.png');
  background-size: 100% 100%;
  padding: 0;
}

.profile-content {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  display: flex;
  align-items: flex-start;
}

.profile-row {
  width: 100%;
  margin: 0 !important;
}

.info-card {
  border: none;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  color: #ffffff;
  transition: all 0.3s ease;
  box-shadow: 0 4px 20px rgba(1, 96, 250, 0.15);

  &:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 30px rgba(1, 96, 250, 0.3);
  }
}

.user-card {
  height: 100%;

  ::v-deep .el-card__body {
    padding: 0;
  }
}

.detail-card {
  height: 100%;

  ::v-deep .el-card__body {
    padding: 20px;
  }
}

.card-header {
  display: flex;
  align-items: center;
  font-size: 18px;
  font-weight: bold;
  color: #ffffff;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
  padding: 15px 20px;

  .header-icon {
    color: #ffffff;
    margin-right: 10px;
    font-size: 20px;
  }
}

.user-avatar-container {
  padding: 25px 20px;
  text-align: center;
  background: linear-gradient(90deg, rgba(140, 174, 251, 0.3), rgba(1, 96, 250, 0.4));
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.user-avatar {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  margin: 0 auto 15px;
  background: linear-gradient(135deg, #8caefb 0%, #0160fa 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  color: white;
  box-shadow: 0 5px 15px rgba(1, 96, 250, 0.4);
}

.user-name {
  font-size: 20px;
  font-weight: bold;
  margin-bottom: 5px;
  color: #fff;
}

.user-role {
  font-size: 14px;
  color: #ffffff;
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: 15px;
  display: inline-block;
}

.info-list {
  list-style: none;
  padding: 20px;
  margin: 0;
}

.info-item {
  display: flex;
  align-items: center;
  padding: 15px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);

  &:last-child {
    border-bottom: none;
  }
}

.info-icon {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-right: 15px;
  color: #ffffff;
  font-size: 18px;
}

.info-content {
  flex: 1;
}

.info-label {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  margin-bottom: 4px;
}

.info-value {
  font-size: 16px;
  color: #fff;
  word-break: break-all;
}

.profile-tabs {
  ::v-deep .el-tabs__header {
    margin-bottom: 25px;
  }

  ::v-deep .el-tabs__nav-wrap::after {
    background-color: rgba(255, 255, 255, 0.1);
  }

  ::v-deep .el-tabs__active-bar {
    background-color: #ffffff;
    height: 3px;
  }

  ::v-deep .el-tabs__item {
    color: rgba(255, 255, 255, 0.7);
    font-size: 16px;
    height: 50px;
    line-height: 50px;

    &.is-active {
      color: #ffffff;
      font-weight: bold;
    }

    &:hover {
      color: #ffffff;
    }
  }
}

.tab-label {
  display: flex;
  align-items: center;

  i {
    margin-right: 8px;
    font-size: 18px;
  }
}

/* 响应式设计 */
@media (max-width: 768px) {
  .profile-content {
    padding: 10px;
  }

  .user-avatar {
    width: 60px;
    height: 60px;
    font-size: 30px;
  }

  .info-item {
    padding: 12px 0;
  }

  .info-icon {
    width: 36px;
    height: 36px;
    font-size: 16px;
  }
}
::v-deep .el-radio__label {
  color: #fff;
}
::v-deep .el-radio__input.is-checked + .el-radio__label {
  color: #00f6ff;
}
::v-deep .el-form-item__label {
  color: rgba(255, 255, 255, 0.8) !important;
}
</style>

<!-- 全局卡片样式优化 -->
<style lang="scss">
.el-card {
  border: none;

  &.info-card {
    .el-card__header {
      border-bottom: 1px solid rgba(255, 255, 255, 0.2);
      //background: linear-gradient(90deg, #0087fe, #17bff7);
    /*  background: linear-gradient(90deg, #8caefb, #0160FA);*/
     /* background:#00afff;*/
      color: #ffffff;
    }
  }
}

/* 表单输入框透明样式 */
.el-input {
  .el-input__inner {
    background-color: rgba(255, 255, 255, 0.15) !important;
    border-color: rgba(255, 255, 255, 0.3);
    color: #ffffff;

    &::placeholder {
      color: rgba(255, 255, 255, 0.5);
    }

    &:hover {
      border-color: #ffffff;
    }

    &:focus {
      border-color: #ffffff;
      box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
    }
  }

  .el-input__prefix,
  .el-input__suffix {
    color: rgba(255, 255, 255, 0.7);
  }
}

//.el-form-item__label {
//  color: rgba(255, 255, 255, 0.8) !important;
//}

.el-textarea {
  .el-textarea__inner {
    background-color: rgba(255, 255, 255, 0.15) !important;
    border-color: rgba(255, 255, 255, 0.3);
    color: #ffffff;

    &::placeholder {
      color: rgba(255, 255, 255, 0.5);
    }

    &:hover {
      border-color: #ffffff;
    }

    &:focus {
      border-color: #ffffff;
      box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.2);
    }
  }
}

/* 按钮样式优化 */
.el-button--primary {
  background-color: #0160fa;
  border-color: #0160fa;

  &:hover {
    background-color: lighten(#0160fa, 5%);
    border-color: lighten(#0160fa, 5%);
  }

  &:active {
    background-color: darken(#0160fa, 5%);
    border-color: darken(#0160fa, 5%);
  }
}

</style>
